/**
 *
 */
package com.levy.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;


/**
 * 
 * @author levy.xia
 *
 */
@Entity(name = "dm_role")
public class Role implements Serializable {

    /**
     * the serialVersionUID.
     */
    private static final long serialVersionUID = -7043265515827415554L;

    /**
     * the role id.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sq_role")
    @SequenceGenerator(name = "sq_role", sequenceName = "dm_sq_user_role")
    private Integer id;

    /**
     * the role name.
     */
    private String name;

    /**
     * is the report template role?
     */
    private Integer istemplate;

    /**
     * the role description.
     */
    @Column(name = "description", length = 500)
    private String description;

    /**
     * the resources of this role.
     */
    @ManyToMany(targetEntity = Resource.class, fetch = FetchType.EAGER)
    @JoinTable(name = "dm_role_resource", joinColumns = @JoinColumn(name = "role_id"),
               inverseJoinColumns = @JoinColumn(name = "resource_id"))
    private Set<Resource> resources;

    /**
     * The default constructor.
     */
    public Role() {

    }

    /**
     * @return the id
     */
    public final Integer getId() {
        return id;
    }

    /**
     * @return the name
     */
    public final String getName() {
        return name;
    }

    /**
     * @return the description
     */
    public final String getDescription() {
        return description;
    }

    /**
     * @return the resources
     */
    public final Set<Resource> getResources() {
        return resources;
    }

    /**
     * @param id the id to set
     */
    public final void setId(final Integer id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public final void setName(final String name) {
        this.name = name;
    }

    /**
     * @param description the description to set
     */
    public final void setDescription(final String description) {
        this.description = description;
    }

    /**
     * @param resources the resources to set
     */
    public final void setResources(final Set<Resource> resources) {
        this.resources = resources;
    }

    /**
     *
     * @return 0 if this role is a template role, otherwise return 1
     */
    public final Integer getIstemplate() {
        return istemplate;
    }

    /**
     *
     * @param istemplate  new value
     */
    public final void setIstemplate(final Integer istemplate) {
        this.istemplate = istemplate;
    }

}
